//
//  AppDelegate.m
//  Coco_Music
//
//  Created by K。 on 15/6/19.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "AppDelegate.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"
#import "WeiboApi.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

-(void)dealloc
{
    [_window release];
    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [self NetWork];
    
    CustomTabBarController *TabBar = [[CustomTabBarController alloc]init];
    self.window.rootViewController = TabBar;
    [TabBar release];
    
 
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setActive:YES error:nil];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[UIApplication sharedApplication]beginReceivingRemoteControlEvents];
    
    

    //开机动画
    static BOOL number=0;
    NSUserDefaults *library=[NSUserDefaults standardUserDefaults];
    
    if ([library objectForKey:@"libraryNumber"]==nil){
        
        [library setBool:number forKey:@"libraryNumber"];
        
        NSArray *coverImageNames = @[@"IMG_1154_2.png", @"IMG_1155_2.png", @"IMG_1166_2.png"];
        NSArray *backgroundImageNames =  @[@"IMG_1154.png", @"IMG_1155.png", @"IMG_1156.png"];
        NSLog(@"走没走");
        
        self.introductionView = [[ZWIntroductionViewController alloc]initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        [self.window addSubview:self.introductionView.view];
        
        __weak AppDelegate *weakSelf = self;
        self.introductionView.didSelectedEnter = ^() {
            [weakSelf.introductionView.view removeFromSuperview];
            weakSelf.introductionView = nil;
            // enter main view , write your code ...
            //        ViewController *mainVC = [[ViewController alloc] init];
            //        weakSelf.window.rootViewController = mainVC;
            
            NSLog(@"没走啊");
            
        };
    }
    
    
    
    
#pragma 三方分享
    
    
    
    [ShareSDK registerApp:@"api20"];//字符串api20为您的ShareSDK的AppKey
    
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"63403026"
                               appSecret:@"6cc7d17bb5d1f238790ae5d74307842a"
                             redirectUri:@"http://www.lanou3g.com"];
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
    [ShareSDK  connectSinaWeiboWithAppKey:@"63403026"
                                appSecret:@"6cc7d17bb5d1f238790ae5d74307842a"
                              redirectUri:@"http://www.lanou3g.com"
                              weiboSDKCls:[WeiboSDK class]];
    
    
    [ShareSDK connectTencentWeiboWithAppKey:@"801525832"
                                  appSecret:@"76ace6757744edb607df33cc48d7543c"
                                redirectUri:@"http://www.lanou3g.com"wbApiCls:[WeiboApi class]];
    
    
    
    

    
    
    
    
    

    [_window release];
    return YES;
}

-(void)NetWork
{
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
            case AFNetworkReachabilityStatusNotReachable:
                [Network shareSingleton].statu = @"lost_internet";
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"1");
                UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"正在使用手机流量,建议切换到WIFI" delegate:self cancelButtonTitle:@"土豪请忽略" otherButtonTitles: nil];
                [alert1 show];
                [alert1 release];
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                
                break;
        }
    }];
    
    [mgr startMonitoring];
    
}





- (void)applicationDidEnterBackground:(UIApplication *)application {
    
    [application beginBackgroundTaskWithExpirationHandler:nil];
    
    
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
    if (event.type == UIEventTypeRemoteControl) {
        
        switch (event.subtype) {
            case UIEventSubtypeRemoteControlPause:
                [[PlayingViewController shareHandleController].STKPlayer pause];
                NSLog(@"暂停了播放了");
                break;
                case UIEventSubtypeRemoteControlPlay :
                [[PlayingViewController shareHandleController].STKPlayer resume];
                break;
                case UIEventSubtypeRemoteControlPreviousTrack:
              
                 [[PlayingViewController shareHandleController] preButtonEvent];
                NSLog(@"上一曲");
                break;
                case UIEventSubtypeRemoteControlNextTrack:
                [[PlayingViewController shareHandleController] nextButtonEvent];
                NSLog(@"下一曲");
                default:
                break;
        }
        
    }
}



- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url wxDelegate:nil];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:nil];
}





- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
